package com.practice.J2E.thread;

import java.util.List;

/**
 * 酸奶店
 * @author kayn
 * @create 2023-09-27 下午 03:22
 */
public class Shop {

    private List<String> yogurtList;

    private volatile Boolean shopStatus;

    /**
     * 开张
     * @return
     */
    public static Shop openShop(List<String> yogurtList,int yogurt) {
        Shop shop = new Shop();

        shop.yogurtList = yogurtList;

        shop.shopStatus = Boolean.FALSE;

        System.out.println("酸奶店开张！今日预计制作" + yogurt + "杯酸奶~");

        return shop;
    }

    /**
     * 开始制作
     * @return
     */
    public void startMaking() {

        shopStatus = Boolean.TRUE;

        System.out.println("开始制作酸奶！");
    }

    /**
     * 制作一杯酸奶
     * @return
     */
    public void makeYogurt(String yogurtName) {

        yogurtList.add(yogurtName);

        System.out.println("\n" + yogurtName + "制作完成,当前剩余酸奶" + yogurtList);
    }

    /**
     * 售出一杯酸奶
     * @return
     */
    public void SellYogurt(String buyerName){

        String yogurt = yogurtList.get(0);

        yogurtList.remove(yogurt);

        System.out.println(buyerName + "买到了" + yogurt + ",并给出了好评！");

        if (!shopStatus) {
            this.notifyAll();
        }
    }

    /**
     * 结束制作
     * @return
     */
    public void stopMaking() {

        shopStatus = Boolean.FALSE;

        System.out.println("停止制作酸奶！");

    }

    public List<String> getYogurtList() {
        return yogurtList;
    }

    public Boolean getShopStatus() {
        return shopStatus;
    }
}
